# -*- coding:utf-8 -*-
import random
import time

from Util import config, logger
from PageClass.configIndexPage.interfacePlatformPage import TimerManagePage


class HandleTimer(object):

    def __init__(self, driver):
        self.driver = driver
        self._timerManage = TimerManagePage(self.driver)

    def goToTimerPage(self):
        self._timerManage.driver.get(config.urlDict.url.timerHost)
        time.sleep(random.random())

    def runTimer(self, timerType, timerName):
        logger.info(f'准备开始运行定时器，运行的目标定时器为：{timerName}')
        self._timerManage.click_timerTab(timerType)
        self._timerManage.input_selectTimerName(timerName)
        self._timerManage.click_selectButton()
        if not self._timerManage.click_runTimer():
            logger.error(f'{timerName} 定时器运行失败')
        self._timerManage.back()
